#include "NewVersionMsg.h"
#include "CurrentAppHeaders.h"

NewVersionMsg::NewVersionMsg() 
{
    m_parent = NULL;
    m_isNewVersionAvailable = false;
}
void NewVersionMsg::ShowInMessageBox()
{
                m_content = GETLANG(105)                 //new version available.message
                                                        + GETLANG(104) + wxGetApp().GetStrVersion(2) + wxT("\n") //current version.message
                                                        + GETLANG(103) + m_newVersion + wxT("\n\n")      //available version.message
                                                        + GETLANG(102);

    wxString urlDownload = m_urlsToDownload[0];
    if ( wxMessageBox( m_content, m_title, wxICON_INFORMATION | wxYES_NO) == wxYES)
        wxLaunchDefaultBrowser(urlDownload);                //opens the web address in browser

}
void NewVersionMsg::ShowInMultipleChoises()
{
    
    m_content = GETLANG(105)                 //new version available.message
                + GETLANG(104) + wxGetApp().GetStrVersion(2) + wxT("\n") //current version.message
                + GETLANG(103) + m_newVersion + wxT("\n\n")      //available version.message
                + GETLANG(106);

    
    int count = wxGetMultipleChoices(
        m_itemsSelection,
        m_content,
        m_title,
        m_descriptionsToShow,
        m_parent, wxDefaultCoord, wxDefaultCoord,true,100,100
    );
    //m_parent = NULL;
    
    if (count)
    {
        wxString currentUrl;
        int n, c;
        for ( n = 0; n < count; n++ )
        {
            currentUrl = m_urlsToDownload[m_itemsSelection[n]];
            if ( currentUrl.Len() > 0 )
            {
                wxLaunchDefaultBrowser( currentUrl );
                for ( c = n+1; c < count ; c++)
                    if ( m_urlsToDownload[c] == currentUrl )
                        m_urlsToDownload[c] = wxT("");
            }
        }
    }

}
void NewVersionMsg::ShowInBalloonTooltip()
{
    wxString urlDownload = wxT("");
    if ( m_urlsToDownload.GetCount() > 0 )
        urlDownload = m_urlsToDownload[0];
    
    if ( wxGetApp().m_Mode != HIDDENMODE )
    {
        wxGetApp().ManageIcon(1,urlDownload);
    }
    wxGetApp().ChangeMsgBalloon(
        0,GETLANG(105)
        //+ GETLANG(104) + wxGetApp().GetStrVersion(2) + wxT("\n") //current version.message
        + GETLANG(103) + m_newVersion + wxT("\n\n")      //available version.message
        + GETLANG(107)
        ,false, (wxGetApp().m_Mode == CONFIGMODE? false : true  ),true
    );
}

void NewVersionMsg::ShowMessage()
{
    wxGetApp().m_IsInputFinished = false;

    m_title = GETLANG(101) + wxT(" - TNod");
    if ( m_descriptionsToShow.GetCount() > 1 ) //if the list of distributions of the new version is more of one
    {
        ShowInMultipleChoises();
    }
    else //if exists one distribution only
    {
        ShowInMessageBox();
    }
    wxGetApp().m_IsInputFinished = true;
}
